#ifndef _USART_0_H_
#define _USART_0_H_
#include <stdint.h>
#include <stddef.h>
#include <dataIO.h>
#include <avr/io.h>
#include <ringBuffer.h>
#include <avr/interrupt.h>
#include <system.h>

extern RingBuffer usart0InBuffer;
extern RingBuffer usart0OutBuffer;

void usart0_write(char c);

class USART0 : public DataInput, public DataOutput {
public:
	USART0(int32_t baudRate);

	size_t available() {
		return usart0InBuffer.available();
	}

	size_t freeSpace() {
		return usart0OutBuffer.freeSpace();
	}

	char read() {
		return usart0InBuffer.read();
	}

	void clear() {
		usart0InBuffer.clear();
	}

	/*
	size_t available() {
		return usart0InBuffer.available();
	}

	char read() {
		return usart0InBuffer.read();
	}

	void clear() {
		usart0InBuffer.clear();
	}

	size_t freeSpace() {
		return usart0OutBuffer.freeSpace();
	}

	void write(char data) {
		usart0_write(data);
	}
	*/

	bool tryWrite(char data) {
		if (usart0OutBuffer.freeSpace()) {
			usart0_write(data);
			return true;
		}
		return false;
	}
};

#endif
